require 'dgo/tile_map/map'
require 'dgo/tile_map/map_layer'
module MapEditor
  class Model
    attr_reader :auto_chipsets
    attr_reader :tile_x_count, :tile_y_count, :grid_width, :grid_height
    attr_reader :map_id, :layers, :map
    
    attr_reader :panorama_texture
    attr_accessor :base_chipset, :anime_chipset, :panorama
    include DGO::TileMap
    def initialize(id, data)
      @map_id = id
      @map = DGO::TileMap::Map.new(data[:x_count], data[:y_count], 1, 1, data[:grid_width], data[:grid_height], data[:collision_data], 3, 1, :editor, 0)
      
      @layers = [] 
      
      data[:layers].each do |layer|
        @layers << MapLayer.new(@map, layer)
      end

      @base_chipset = data[:base_chipset]
      @anime_chipset = data[:anime_chipset]
      
      @auto_chipsets = data[:auto_chipsets]
      
      @panorama = data[:panorama]
    end

    def grid_width
      @map.grid_width.to_f
    end
    
    def grid_height
      @map.grid_height.to_f
    end
    
    def tile_x_count
      @map.x_count
    end
    
    def tile_y_count
      @map.y_count
    end
    
    def set_map_size(x_count, y_count)
      map.set_size(x_count, y_count, @layers)
      map.refresh_textures
    end
  end
end